package com.top4create.webapp.controller;

import com.top4create.service.GenericManager;
import com.top4create.model.FavourateCompany;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

@Controller
@RequestMapping("/favourateCompanies*")
public class FavourateCompanyController {
    private GenericManager<FavourateCompany, Long> favourateCompanyManager;

    @Autowired
    public void setFavourateCompanyManager(@Qualifier("favourateCompanyManager") GenericManager<FavourateCompany, Long> favourateCompanyManager) {
        this.favourateCompanyManager = favourateCompanyManager;
    }

    @RequestMapping(method = RequestMethod.GET)
    public ModelAndView handleRequest(@RequestParam(required = false, value = "q") String query)
    throws Exception {
        return new ModelAndView().addObject(favourateCompanyManager.search(query, FavourateCompany.class));
    }
}
